#include <cstdio>
#include <memory>
#include "pkg.h"
#include "basis.h"
#include "data_center.h"
#include "processing.h"
#include "insert_order.h"
#include "cancel_order.h"
#include "transfer_order.h"

int main(int argc, char const* argv[])
{
    // 数据中心的初始化(内存表)
    std::shared_ptr<data_center_t> data_center_sptr = std::make_shared<data_center_t>();

    // 创建一个市场实例
    std::shared_ptr<xmarket_t> market = std::make_shared<basis_t>();
    
    // 定义处理器
    auto processing1 = std::make_shared<pricing_client_check_t>(data_center_sptr);
    auto processing2 = std::make_shared<client_id_corrected_t>(data_center_sptr);
    auto processing3 = std::make_shared<contract_exist_check_t>(data_center_sptr);

    using xproclist_t = std::initializer_list<std::shared_ptr<xprocessing_t>>;
    //auto proc = std::make_shared<xprocessing_t>(std::initializer_list<std::shared_ptr<xprocessing_t>>{processing1, processing2, processing3});
    auto proc = std::make_shared<xprocessing_t>(xproclist_t{processing1, processing2, processing3});

    // 定义业务
    //auto biz = std::make_shared<insert_order_t>();

    // 初始化产品
    market->init();
    // 为产品添加消息处理器， 消息TID映射到业务, 为业务处理器指定具体的处理规则
    market->add_biz(0x1001, std::make_shared<insert_order_t>(proc));
    market->add_biz(0x1002, std::make_shared<cancel_order_t>(processing2));

    // 收到一个数据包，开始处理
    pkg data;
    data.tid=0x1001;
    data.a = 102;
    market->handle_input(data);

    return 0;
}
